/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jard.webshop.jsfbeans;

import jard.webshop.nbp.Product;
import jard.webshop.management.ProductManagement;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Harteex (with a little help from johaolof)
 */
@ManagedBean(name = "productListingBacking")
@RequestScoped
public class ProductListingBacking {
    private List<Product> products;
    @ManagedProperty(value = "#{userModelBean}")
    private UserModelBean user;

    /** Creates a new instance of ProductListingBacking */
    public ProductListingBacking() {
    }
    
    public List<Product> getProducts() {
        // Not strictly speaking necessary, but in case we want to for ViewScope
        // or something like that at some point. Defensive programming...
        if(products == null) {
            Boolean reallyAll = user != null && (user.isAdmin() || user.isEmployee());
            products = ProductManagement.getInstance().getAllProducts(reallyAll);
        }
        return products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public void setUser(UserModelBean user) {
        this.user = user;
    }
}
